<!--
 * @Author: HeAo
 * @Date: 2021-10-11 09:20:08
 * @LastEditTime: 2021-10-11 10:03:54
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day03\1-组件基础.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- 3.组件的使用 -->
    <!-- <my-button></my-button>
    <my-button></my-button>
    <my-button></my-button>
    <my-button></my-button> -->
    <you-button data="hello"></you-button>
    <!-- <my-button></my-button> -->
  </div>
  <script>
    // 1.组件定义
    let component1 = {
      data() {
        return {
          msg: '我是组件数据'
        }
      },
      // 数据模型是个普通对象，会导致复用组件时，各个组件内部的数据会相互影响
      // data: {
      //   msg: '我是组件数据'
      // },
      template: `<div>
          <button @click="msg = 'hello'">{{msg}}</button>
          <button @click="msg = 'hello'">{{msg}}123123</button>
        </div>`
    }

    let component2 = {
      data() {
        return {
          msg: '我是组件二数据'
        }
      },
      // 2.2局部注册
      components: {
        'my-button': component1
      },
      template: `<div>
        <button @click="msg = 'hello'">{{msg}}</button>
        <my-button></my-button>
      </div>`
    }

    // 2.组件注册
    // 2.1组件的全局注册
    // Vue.component('my-button', component1)

    let vm = new Vue({
      el: '#app',
      data: {

      },
      methods: {

      },
      created() {

      },
      components: {
        'you-button': component2
      }
    })
  </script>
</body>

</html>